#include <modules\fileTextureModule.h>
#include <model.h>

#include "Poco\DirectoryIterator.h"
#include <Poco\File.h>
#include <Poco\Path.h>

#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;

using Poco::DirectoryIterator;
using Poco::File;
using Poco::Path;

fileTextureModule::fileTextureModule(vec2i _tile_res, vec2i _levels_interval, int _level0_offset, string _datasourcedir) : dataModule() {
  tile_res = _tile_res;
  levels_interval = _levels_interval;
  datasourcedir = _datasourcedir;
  level0_offset = _level0_offset;
}

bool
fileTextureModule::post(model * _model) {

  Poco::Path dir(_model->getDataStorageDir());
  dir.pushDirectory(_model->getModelName());

  Poco::File ofile(Poco::Path(dir.absolute(), _model->getModelName() + ".def"));

  ofstream output(ofile.path().c_str(), ios::app | ios::out | ios::binary);

  output << "fileTextureModule" << endl;
  output << tile_res[0] << endl;
  output << tile_res[1] << endl;
  output << levels_interval[0] << endl;
  output << levels_interval[1] << endl;
  output << level0_offset << endl;

  output.close();

  return true;
}